import {createRouter, createWebHistory} from 'vue-router'


const routes =reactive([
    {
        path: '/',
        name: 'login',
        component: () => import('@/views/system/login/Login.vue')
    },
    {
        path: "/layout",
        name: "layout",
        component: () => import('@/views/system/layout/Layout.vue'),
    }
])

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: routes
})
import {setMiniMenu, adminMenu,teacherMenu,studentMenu,technicianMenu} from "@/views/system/layout/Layout"
import {reactive} from "vue";
export const setAllMiniMenu=()=>{
    setMiniMenu(adminMenu,"layout", router);
    setMiniMenu(teacherMenu,"layout", router);
    setMiniMenu(studentMenu,"layout", router);
    setMiniMenu(technicianMenu,"layout", router);
}



router.beforeEach(async (to, form, next) => {
    if (to.path != '/') {
        let token = sessionStorage.getItem('token')
        if (!token) {
            router.push('/')
        }
    } else {
        let token = sessionStorage.getItem('token')
        if (token) {
            router.push('/layout')
        }
    }

    next()
})
router.afterEach((to, from) => {

})
export default router
